import request from "@/utils/request-gis";
import request_inspection from "@/utils/request-inspection";
import request_file from "@/utils/request-file";
import { FileInfo } from "@/api/file/model";

const blobConfigWithoutFormData = {
  responseType: "blob",
};

export function addPoint(data: any) {
  return request({
    url: "/api/GisPointInfo/AddAsync",
    method: "post",
    data,
  });
}

export function queryPoints(params: any) {
  return request({
    url: "/api/GisPointInfo/QueryJsonGeomAsync",
    method: "post",
    data: params,
  });
}

export function queryPointsPro(params: any) {
  return request({
    url: "/api/GisPointInfo/QueryAsync",
    method: "post",
    data: params,
  });
}

export function updatePoint(params: any) {
  return request({
    url: "/api/GisPointInfo/UpdateAsync",
    method: "post",
    data: params,
  });
}
export function movePoint(params: any) {
  return request({
    url: "/api/GisPointInfo/MoveAsync",
    method: "post",
    data: params,
  });
}
export function deletePoint(pointId: number) {
  return request({
    url: "/api/GisPointInfo/DeleteAsync",
    method: "post",
    data: { pointId },
  });
}

export function addPolyline(data: any) {
  return request({
    url: "/api/GisLineInfo/AddAsync",
    method: "post",
    data,
  });
}
export function queryPolylines(params: any) {
  return request({
    url: "/api/GisLineInfo/QueryJsonGeomAsync",
    method: "post",
    data: params,
  });
}

export function queryPolylinesPro(params: any) {
  return request({
    url: "/api/GisLineInfo/QueryAsync",
    method: "post",
    data: params,
  });
}

export function updatePolyline(params: any) {
  return request({
    url: "/api/GisLineInfo/UpdateAsync",
    method: "post",
    data: params,
  });
}
export function deletePolyline(lineId: number) {
  return request({
    url: "/api/GisLineInfo/DeleteAsync",
    method: "post",
    data: { lineId },
  });
}

export function getSysDictionaryByType(data: {
  pageSize: number;
  pageIndex: number;
  dicTypeId: number;
}) {
  return request({
    url: "/api/SysDictionary/QueryAsync",
    method: "post",
    data,
  });
}

export function addArea(data: {
  polygonName: string;
  polygonType: number;
  jsonPolygon: string;
}) {
  return request({
    url: "/api/GisPolygonInfo/AddAsync",
    method: "post",
    data,
  });
}

export function queryAreaInfoList(params: {
  pageSize: number;
  pageIndex: number;
  polygonType: number | null;
}) {
  return request({
    url: "/api/GisPolygonInfo/QueryJsonGeomAsync",
    method: "post",
    data: params,
  });
}

export function deleteAreaById(params: { polygonId: number }) {
  return request({
    url: "/api/GisPolygonInfo/DeleteAsync",
    method: "post",
    data: params,
  });
}

export function isOverlapArea(params: {
  polygonType: number;
  jsonPolygon: string;
  polygonId: number;
}) {
  return request({
    url: "/api/GisPolygonInfo/IsOverlapAsync",
    method: "post",
    data: params,
  });
}

export function fuzzySearch(data: {
  pageSize: number;
  pageIndex: number;
  queryVal: string;
}) {
  return request({
    url: "api/GisCommonInterface/QueryJsonGeomByPointLinePolygonAsync",
    method: "post",
    data,
  });
}

/**
 * 孤立点检测
 * @param data
 */
export function querySinglePoints(data: any) {
  return request({
    url: "/api/GisPointInfo/SolitaryPointDetectionListAsync",
    method: "post",
    data,
  });
}

/**
 * 重叠点检测
 * @param data
 */
export function queryOverlapPoints(data: any) {
  return request({
    url: "/api/GisPointInfo/OverlapPointDetectionListAsync",
    method: "post",
    data,
  });
}

/**
 * 悬挂线检测
 */
export function querySuspensionLines(data: any) {
  return request({
    url: "/api/GisLineInfo/SuspensionLineDetectionListAsync",
    method: "post",
    data,
  });
}
/**
 * 发布管点、管段
 */
export function publish() {
  return request({
    url: "/api/GisCommonInterface/PublishAsync",
    method: "post",
    data: {},
  });
}
/* ----------------------------巡检路线------------------------ */

/**
 * 新增或编辑巡检路线
 * @param data
 */
export function editInspectionRoute(data: {
  inspLineId?: number;
  inspLineName: string;
  inspLineType: number;
  startPositionId: number;
  startPositionName: string;
  byWay: string;
  endPositionId: number;
  endPositionName: string;
  jsonLine: string;
  inspPositionCount: number;
}) {
  return request_inspection({
    url: "/api/line-set/edit",
    method: "post",
    data,
  });
}

/**
 * 查询巡检路线列表
 * @param data
 */
export function queryInspectionRouteList(data: any) {
  return request_inspection({
    url: "/api/line-set/page",
    method: "get",
    params: data,
  });
}

/**
 * 删除巡检路线
 * @param id
 */
export function deleteInspectionRoute(id: number) {
  return request_inspection({
    url: `/api/line-set/${id}`,
    method: "Delete",
  });
}

/**
 * 复制巡检路线
 * @param id
 */
export function copyInspectionRoute(id: number) {
  return request_inspection({
    url: `/api/line-set/copy/${id}`,
    method: "post",
    data: {},
  });
}

/* ----------------------------专题展示、资产统计------------------------ */

/**
 * 管线统计列表
 **/
export function statisticsPipeLineList(data) {
  return request({
    url: "/api/GisLineStatistics/GetGisLineStatisticsListAsync",
    method: "post",
    data,
  });
}

/**
 * 统计管段长度
 * @param data
 */
export function statisticsPipeLineLength(data) {
  return request({
    url: "/api/GisLineStatistics/GetGisLineStatisticsLengthAsync",
    method: "post",
    data,
  });
}
/**
 * 统计管段数量
 * @param data
 */
export function statisticsPipeLineNum(data) {
  return request({
    url: "/api/GisLineStatistics/GetGisLineStatisticsNumAsync",
    method: "post",
    data,
  });
}

/**
 * 导出:管段资产表
 * @param data
 */
export function exportPipeLineList(data) {
  return request.post(
    "/api/GisLineStatistics/ExportGisLineStatisticsListAsync",
    data,
    blobConfigWithoutFormData
  );
}
/**
 * 管点统计列表
 **/
export function statisticsPipePointList(data) {
  return request({
    url: "/api/GisPointStatistics/GetGisPointStatisticsListAsync",
    method: "post",
    data,
  });
}
/**
 * 统计管点数量
 * @param data
 */
export function statisticsPipePointNum(data) {
  return request({
    url: "/api/GisPointStatistics/GetGisPointStatisticsNumAsync",
    method: "post",
    data,
  });
}
/**
 * 导出:管点资产表
 * @param data
 */
export function exportPipePointList(data) {
  return request.post(
    "/api/GisPointStatistics/ExportGisPointStatisticsListAsync",
    data,
    blobConfigWithoutFormData
  );
}

export function exportAllDevices(data) {
  // return request.post(
  //   "/api/GisCommonInterface/ExportAllQueryAsync",
  //   data,
  //   responseType: "blob",
  // );

  return request({
    url: "/api/GisCommonInterface/ExportAllQueryAsync",
    method: "post",
    data: data,
    responseType: "blob",
  });
}

/**
 * 查询:主要返回区域坐标信息
 */
export function queryShadePolygon(data) {
  return request({
    url: "/api/GisInitPolygonInfo/QueryJsonGeomAsync",
    method: "post",
    data,
  });
}

export function uploadImg(file) {
  const formData = new FormData();
  formData.append("file", file);
  return request_file<any, FileInfo>({
    url: "/api/resource/upload-image",
    method: "post",
    data: formData,
    headers: {
      "Content-Type": "multipart/form-data",
    },
  });
}
